<template>
  <div class="select-related-container">
    <InvoiceAndContract
      ref="ContractSelect"
      :type="1"
      title="合同信息"
      show-empty
      placeholder="请输入合同编号/合同名称">
      <!-- <div v-if="showOrderInfo" slot="btn-group">
        <el-button type="primary" size="small" class="relevance-btn" @click="getOrderRelatedContract">获取订单合同</el-button>
      </div> -->
    </InvoiceAndContract>
  </div>
</template>

<script>
import InvoiceAndContract from '@/components/CreateOrder/InvoiceAndContract';
import { showModal } from '@/utils/message';
export default {
  name: 'ContractInfo',
  components: {
    InvoiceAndContract
  },
  props: {
    showOrderInfo: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    getContractIds() {
      const contractSelect = this.$refs['ContractSelect'];
      let contractIds = [];
      if (contractSelect && contractSelect.selectData) {
        contractIds = contractSelect.selectData.map(i => i.id);
      }
      return contractIds.join(',');
    },
    setContractInfo(list) {
      this.$refs['ContractSelect'].setDefault(list);
    },
    getOrderRelatedContract() {
      showModal('请确认是否获取订单所关联合同？', '', {}).then(_ => {
        this.$emit('getOrderRelatedContract');
      });
    },
    relationContract(list) {
      const contractSelect = this.$refs['ContractSelect'];
      let contractIds = [];
      if (contractSelect && contractSelect.selectData) {
        contractIds = contractSelect.selectData.map(i => i.id);
      }
      const filterList = list.filter(item => contractIds.every(id => id !== item.id));
      const result = contractSelect.selectData.concat(filterList);
      this.$refs['ContractSelect'].setDefault(result);
      this.$message.success('关联成功');
    }
  }
};
</script>

<style scoped lang="scss">
.select-related-container {
  margin-top: 8px;
  position: relative;
  padding-bottom: 32px;
  .relevance-btn {
    margin-right: 10px;
    padding-left: 8px;
    padding-right: 8px;
    background-color: #fff;
    color: #406EFF;
  }
}
</style>
